package com.whut.gkd.controller;

import com.whut.gkd.bean.ApplyShop;
import com.whut.gkd.bean.PageInfo;
import com.whut.gkd.service.IApplyShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("applyshop")
public class ApplyShopController {

    @Autowired
    private IApplyShopService applyshopService;

    @RequestMapping("findAll.do")
    public ModelAndView findAll(@RequestParam(defaultValue = "1") int currentPage, String applicanName,
                                @RequestParam(defaultValue = "0") int type,
                                HttpSession session){
//        int applicanid;
//        if(applicanId == null){
//            applicanid = 0;
//        }else{
//            applicanid = Integer.valueOf(applicanId);
//        }
//        //转换为int
//        Integer integer = new Integer(applyid);
//        int apply = integer.intValue();

        if(type==1) {
            session.setAttribute("applicanName", applicanName);
        }else if(type==0){
            if(session.getAttribute("applicanName") != null){
                applicanName= (String) session.getAttribute("applicanName");
            }
        }else if(type==2){
            session.removeAttribute("applicanName");
        }
        PageInfo<ApplyShop> pageInfo=applyshopService.findAll(currentPage,applicanName);
        ModelAndView mv=new ModelAndView();
        mv.setViewName("shopmanager");
        mv.addObject("pageInfo",pageInfo);
        //mv.addObject("objList",pageInfo.getList());
        return mv;
    }
    @RequestMapping("allowshopByapplicanId.do")
    public String allowshopByapplicanId(int applicanId){
        applyshopService.allowshopByapplicanId(applicanId);
        applyshopService.deleteByapplicanId(applicanId);

        return  "redirect:findAll.do";
    }

    @RequestMapping("rejectshopByapplicanId.do")
    public String rejectshopByapplicanId(int applicanId){

        applyshopService.deleteByapplicanId(applicanId);
        return  "redirect:findAll.do";
    }



}